function all(params) {
    let p = Array.from(params)
    let i = 0
    let ret = []
    let len = p.length
    return new Promise((resolve, reject) => {
        for (let e of p) {
            Promise.resolve(e).then(data => {
                ret.push(data)
                i++
                if (len === i) {
                    resolve(ret)
                }
            }).catch(e => {
                reject(e)
            })
        }
    })
}
Promise.prototype.all = all
let pro1 = Promise.resolve(1)
let pro2 = new Promise(function (resolve, reject) {
    setTimeout(resolve, 100, 'foo')

})


// ---------
function promiseAll(promises) {
    return new Promise(function (resolve, reject) {
        if (!isArray(promises)) {
            return reject(new TypeError('arguments must be an array'));
        }
        var resolvedCounter = 0;
        var promiseNum = promises.length;
        var resolvedValues = new Array(promiseNum);
        for (var i = 0; i < promiseNum; i++) {
            (function (i) {
                Promise.resolve(promises[i]).then(function (value) {
                    resolvedCounter++
                    resolvedValues[i] = value
                    if (resolvedCounter == promiseNum) {
                        return resolve(resolvedValues)
                    }
                }, function (reason) {
                    return reject(reason)
                })
            })(i)
        }
    })
}
